﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class EditPGJGControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        MPPersistence Persistence1;
        TextBox txtID, txt单位名称;
        DropDownList ddl单位类别;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Persistence1 = (MPPersistence)FindControl("Persistence1");
            txtID = (TextBox)FindControl("txtID");
            ddl单位类别 = (DropDownList)FindControl("ddl单位类别");
            txt单位名称 = (TextBox)FindControl("txt单位名称");
            Panel panel1 = (Panel)FindControl("panel1");
            string cid = base.Page.Request["CID"];
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "zs_company";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["CID"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
                BindDLL();
            }
            Persistence1.BindControl = panel1;
            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsSZSB(userid))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "displaytr", "<script>displaytr();</script>");
            }
            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btnSave_Click);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string cid = base.Page.Request["CID"];
            if (string.IsNullOrEmpty(cid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } else { txtID.Text = cid; }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string cid = base.Page.Request["CID"];
            if (string.IsNullOrEmpty(cid)) {
                if (_EluZSDataProvider.ckuserinrole(cid)) {
                    _EluZSDataProvider.checkuserrole("PG", "评估机构", cid, txt单位名称.Text, "");
                }
            }
            Persistence1.Update();
            HttpContext.Current.Response.Redirect("PGJGList.aspx");
        }
        protected void BindDLL()
        {
            DataTable dt = _EluZSDataProvider.GetParamYB("单位类别", " and keyname='评估机构' ");
            ddl单位类别.DataSource = dt;
            ddl单位类别.DataTextField = "KEYNAME";
            ddl单位类别.DataValueField = "KEYNAME";
            ddl单位类别.DataBind();
        }
    }
}


